import 'package:flutter/material.dart';

/// 应用主题扩展类
/// 用于统一管理应用中的颜色和样式
class AppThemeExtension extends ThemeExtension<AppThemeExtension> {
  // 卡片背景颜色
  final Color cardBackground;
  // 卡片阴影颜色
  final Color cardShadow;
  // 次要文本颜色
  final Color textSecondary;
  // 分割线颜色
  final Color divider;
  // 卡片边框色
  final Color cardBorder;
  // 内容区域背景色
  final Color contentBackground;
  // 统计数字颜色（不同状态）
  final Color successText;
  final Color warningText;
  final Color errorText;
  final Color infoText;
  final Color disabledText;
  
  // 图标背景色（不同状态）
  final Color successBg;
  final Color warningBg;
  final Color errorBg;
  final Color infoBg;
  final Color disabledBg;
  
  // 卡片圆角半径
  final double cardRadius;
  // 内部元素圆角半径
  final double elementRadius;
  // 标签圆角半径
  final double tagRadius;

  const AppThemeExtension({
    required this.cardBackground,
    required this.cardShadow,
    required this.textSecondary,
    required this.divider,
    required this.cardBorder,
    required this.contentBackground,
    required this.successText,
    required this.warningText,
    required this.errorText,
    required this.infoText,
    required this.disabledText,
    required this.successBg,
    required this.warningBg,
    required this.errorBg,
    required this.infoBg,
    required this.disabledBg,
    required this.cardRadius,
    required this.elementRadius,
    required this.tagRadius,
  });

  // 亮色模式主题扩展
  static const light = AppThemeExtension(
    cardBackground: Colors.white,
    cardShadow: Color(0x33000000),
    textSecondary: Color(0xFF757575),
    divider: Color(0xFFE0E0E0),
    cardBorder: Color(0xFFEEEEEE),
    contentBackground: Color(0xFFF5F5F5),
    successText: Color(0xFF4CAF50),
    warningText: Color(0xFFFFC107),
    errorText: Color(0xFFF44336),
    infoText: Color(0xFF2196F3),
    disabledText: Color(0xFF9E9E9E),
    successBg: Color(0x1A4CAF50),
    warningBg: Color(0x1AFFC107),
    errorBg: Color(0x1AF44336),
    infoBg: Color(0x1A2196F3),
    disabledBg: Color(0x1A9E9E9E),
    cardRadius: 4.0,
    elementRadius: 4.0,
    tagRadius: 2.0,
  );

  // 暗色模式主题扩展
  static const dark = AppThemeExtension(
    cardBackground: Color(0xFF1E1E1E),
    cardShadow: Color(0x40000000),
    textSecondary: Color(0xFFBBBBBB),
    divider: Color(0xFF424242),
    cardBorder: Color(0xFF2C2C2C),
    contentBackground: Color(0xFF121212),
    successText: Color(0xFF81C784),
    warningText: Color(0xFFFFD54F),
    errorText: Color(0xFFE57373),
    infoText: Color(0xFF64B5F6),
    disabledText: Color(0xFF9E9E9E),
    successBg: Color(0x1A81C784),
    warningBg: Color(0x1AFFD54F),
    errorBg: Color(0x1AE57373),
    infoBg: Color(0x1A64B5F6),
    disabledBg: Color(0x1A9E9E9E),
    cardRadius: 4.0,
    elementRadius: 4.0,
    tagRadius: 2.0,
  );

  @override
  ThemeExtension<AppThemeExtension> copyWith({
    Color? cardBackground,
    Color? cardShadow,
    Color? textSecondary,
    Color? divider,
    Color? cardBorder,
    Color? contentBackground,
    Color? successText,
    Color? warningText,
    Color? errorText,
    Color? infoText,
    Color? disabledText,
    Color? successBg,
    Color? warningBg,
    Color? errorBg,
    Color? infoBg,
    Color? disabledBg,
    double? cardRadius,
    double? elementRadius,
    double? tagRadius,
  }) {
    return AppThemeExtension(
      cardBackground: cardBackground ?? this.cardBackground,
      cardShadow: cardShadow ?? this.cardShadow,
      textSecondary: textSecondary ?? this.textSecondary,
      divider: divider ?? this.divider,
      cardBorder: cardBorder ?? this.cardBorder,
      contentBackground: contentBackground ?? this.contentBackground,
      successText: successText ?? this.successText,
      warningText: warningText ?? this.warningText,
      errorText: errorText ?? this.errorText,
      infoText: infoText ?? this.infoText,
      disabledText: disabledText ?? this.disabledText,
      successBg: successBg ?? this.successBg,
      warningBg: warningBg ?? this.warningBg,
      errorBg: errorBg ?? this.errorBg,
      infoBg: infoBg ?? this.infoBg,
      disabledBg: disabledBg ?? this.disabledBg,
      cardRadius: cardRadius ?? this.cardRadius,
      elementRadius: elementRadius ?? this.elementRadius,
      tagRadius: tagRadius ?? this.tagRadius,
    );
  }

  @override
  ThemeExtension<AppThemeExtension> lerp(
      ThemeExtension<AppThemeExtension>? other, double t) {
    if (other is! AppThemeExtension) {
      return this;
    }
    return AppThemeExtension(
      cardBackground: Color.lerp(cardBackground, other.cardBackground, t)!,
      cardShadow: Color.lerp(cardShadow, other.cardShadow, t)!,
      textSecondary: Color.lerp(textSecondary, other.textSecondary, t)!,
      divider: Color.lerp(divider, other.divider, t)!,
      cardBorder: Color.lerp(cardBorder, other.cardBorder, t)!,
      contentBackground: Color.lerp(contentBackground, other.contentBackground, t)!,
      successText: Color.lerp(successText, other.successText, t)!,
      warningText: Color.lerp(warningText, other.warningText, t)!,
      errorText: Color.lerp(errorText, other.errorText, t)!,
      infoText: Color.lerp(infoText, other.infoText, t)!,
      disabledText: Color.lerp(disabledText, other.disabledText, t)!,
      successBg: Color.lerp(successBg, other.successBg, t)!,
      warningBg: Color.lerp(warningBg, other.warningBg, t)!,
      errorBg: Color.lerp(errorBg, other.errorBg, t)!,
      infoBg: Color.lerp(infoBg, other.infoBg, t)!,
      disabledBg: Color.lerp(disabledBg, other.disabledBg, t)!,
      cardRadius: lerpDouble(cardRadius, other.cardRadius, t)!,
      elementRadius: lerpDouble(elementRadius, other.elementRadius, t)!,
      tagRadius: lerpDouble(tagRadius, other.tagRadius, t)!,
    );
  }
  
  // 辅助方法用于double类型的线性插值
  static double? lerpDouble(double a, double b, double t) {
    return a + (b - a) * t;
  }
} 